//
//  LQStatusToolBar.swift
//  Weibo
//
//  Created by ios on 16/8/12.
//  Copyright © 2016年 ios. All rights reserved.
//

import UIKit
import SnapKit
class LQStatusToolBar: UIView {
    //  转发按钮
    var retweetButton: UIButton?
    //  评论按钮
    var commentButton: UIButton?
    //  赞按钮
    var unlikeButton: UIButton?
    
    //加载数据
    var  statusViewModel:LQStatusViewModel?{
        didSet{
            retweetButton?.setTitle(statusViewModel?.retweetButtonCount, forState: .Normal)
            commentButton?.setTitle(statusViewModel?.commentButtonCount, forState: .Normal)
            unlikeButton?.setTitle(statusViewModel?.unlikeButtonCount, forState: .Normal)
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: -- 添加控件设置约束
    private func setupUI(){
        retweetButton = addChildButton("timeline_icon_retweet", title: "转发")
        commentButton = addChildButton("timeline_icon_comment", title: "评论")
        unlikeButton = addChildButton("timeline_icon_unlike", title: "赞")
        //第一条竖线
        let firstLine = addChildline()
        //第二条竖线
        let SecondLine = addChildline()
        //设置控件约束
        retweetButton!.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton!)
        }
        
        commentButton!.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton!.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeButton!)
        }
        
        unlikeButton!.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.leading.equalTo(commentButton!.snp_trailing)
        }
        
        firstLine.snp_makeConstraints { (make) -> Void in
             make.centerX.equalTo(retweetButton!.snp_trailing)
             make.centerY.equalTo(self)
        }
        
        SecondLine.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentButton!.snp_trailing)
            make.centerY.equalTo(self)
        }
        
    }
    
    //  添加子按钮的通用方法
    private func addChildButton(ImgName:String,title:String) -> UIButton{
        let button = UIButton()
        //  设置图片
        button.setImage(UIImage(named: ImgName), forState: .Normal)
        //  设置背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        //  设置文字与颜色
        button.setTitle(title, forState: .Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        //  设置字体
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        addSubview(button)
        return button
    }
    
    //添加竖线的方法
    private func addChildline() -> UIImageView{
      let ImgView = UIImageView()
      ImgView.image = UIImage(named: "timeline_card_bottom_line")
      addSubview(ImgView)
      return ImgView
    }
}
